package org.dr.st_docker.prototype;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class MyApplicationContextAwareBean implements ApplicationContextAware {
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    // 通过applicationContext创建新的Commmad实例化Bean
    protected Command createCommand() {
        return this.applicationContext.getBean("command", Command.class);
    }

    // 每次调用process时都从容器中获取新的bean实例
    public String process(String state) {
        Command command = createCommand();
        command.setState(state);
         return command.execute();

    }
}
